Skip to content

Support agenthub#921

Merged
tastelikefeet merged 7 commits into
modelscope:mainfrom
tastelikefeet:feat/agenthub
Jul 16, 2026
Merged

Support agenthub#921
tastelikefeet merged 7 commits into
modelscope:mainfrom
tastelikefeet:feat/agenthub

Conversation

@tastelikefeet

@tastelikefeet tastelikefeet commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

命令行用法

# 登录(前置条件;也可用各网络子命令的 --token/--endpoint 覆盖)
ms login --token <your-token>

# 上传本地 agent 文件到远端仓库
#   必填:-f/--framework、-r/--repo
#   可选:-n/--name、--local-dir、--visibility {public,private}(默认 public)、--dry-run、--token、--endpoint
ms-agent agent upload --framework qwenpaw --repo user/my-agent
ms-agent agent upload --framework nanobot --repo user/my-agent --name reviewer \
    --local-dir ./ws --visibility private --dry-run --token <token> --endpoint <url>

# 从远端下载 agent 文件到本地
#   必填:-f/--framework、-r/--repo
#   可选:-n/--name、--local-dir、--target-framework、--dry-run、--token、--endpoint
ms-agent agent download --framework qwenpaw --repo user/my-agent
ms-agent agent download --framework nanobot --repo user/my-agent --name reviewer \
    --local-dir ./ws --target-framework qwenpaw --dry-run

# 后台同步守护进程(默认 push-only)
#   必填:-f/--framework、-r/--repo
#   可选:-n/--name(默认全部 agent)、--local-dir、--pull(双向同步)、--token、--endpoint
ms-agent agent watch --framework qwenpaw --repo user/my-agent
ms-agent agent watch --framework qwenpaw --repo user/my-agent --name reviewer \
    --local-dir ./ws --pull

# 停止 watch 守护进程(无参数)
ms-agent agent stop

# 查看本地状态
#   必填:-f/--framework    可选:--local-dir
ms-agent agent status --framework qwenpaw --local-dir ./ws

# 格式转换(纯本地,无网络)
#   必填:--from-framework、--target-framework
#   可选:--from-name(默认 default)、--target-name(默认同 --from-name)、--local-dir、--out-dir、--dry-run
ms-agent agent convert --from-framework nanobot --target-framework qwenpaw
ms-agent agent convert --from-framework nanobot --target-framework qwenpaw \
    --from-name default --target-name reviewer --local-dir ./src --out-dir ./out --dry-run

# 备份管理
#   backups  可选:-f/--framework、-n/--name、--local-dir
#   restore  必填:--from-backup('last' 或具体备份文件名)    可选:-f/--framework、-n/--name、--local-dir
ms-agent agent backups --framework qwenpaw --name reviewer
ms-agent agent restore --from-backup last --framework qwenpaw --name reviewer --local-dir ./ws

# 列出远端仓库(代码已实现,但尚未 GA,未写入用户文档)
#   可选:--owner、--page(默认 1)、--page-size(默认 10)、--token、--endpoint
ms-agent agent list --owner user --page 1 --page-size 20

支持的框架:qoder, qwenpaw, openclaw, hermes, nanobot, openhuman, ms-agent

网络类子命令(upload / download / watch / list)的凭据统一由 agent.py::execute() 通过 HubConfig(endpoint, token) 解析,缺省回退到 ms login / MODELSCOPE_API_TOKEN / MODELSCOPE_ENDPOINT


测试用例覆盖(tests/agent_hub/

测试文件 范围 场景
test_watch_sync.py 集成测试(真实 API) push/pull/冲突/删除传播/首次同步/空操作/状态持久化/individual-watch 拦截等
test_upload_download.py 集成测试(真实 API) upload/download/dry-run/跨框架转换下载/token 可选下载
test_convert_targetname.py 单元测试 convert 的 --target-name 派生与目标命名
test_cli.py 单元测试(mock client) argparse 路由、参数传递、错误路径、所有子命令
test_merge.py 单元测试 merge_resources:section merger、heartbeat merger、默认模板注入
test_agent_frameworks.py 单元测试 workspace spec:模式匹配、collect、list_agents、apply、全框架覆盖
test_workspace.py 单元测试 WorkspaceSpec 抽象契约、路径遍历防护

conftest.py 提供 remote-skip 机制:未设置 TOKEN 环境变量(或 MODELSCOPE_RUN_REMOTE_TESTS)时自动 skip 标了 @pytest.mark.remote 的集成用例,避免本地无凭据时连远端 hang。当前离线全量:147 passed / 67 skipped。


薄弱点 / 重点测试点

  1. Windows 跨平台:daemon 启动(fork+exec spawn)、stop 文件 + SIGTERM、wmic 查 PID、文件读写编码(非 ASCII 路径/用户名)在 Windows 上是否都正常。
  2. 上传/下载覆盖正确性:本地文件完整上传、下载回来内容一致、能正确覆盖远端/本地已存在的文件。
  3. 指定 -n <name> 的上传/下载正确性:只处理该 agent;本地存在多个 agent 时能正确选中;下载按指定 name 写入。
  4. 参数有效性:缺 required 参数(-f/-r)、无效框架名、非法 repo 格式(非 owner/name)时是否明确报错而非静默/崩溃。
  5. watch 正确性:本地改动被检测并 push 到远端;无变更时不产生多余 commit(空操作/幂等)。
  6. pull 模式(--pull)有效性:远端改动拉取到本地、双向同步、远端删除能传播到本地。
  7. 备份及还原有效性backups 正确列出;restore --from-backup last/指定文件能还原;还原前自动备份当前状态。
  8. 跨框架转换正确性convertdownload --target-framework 的格式互转、默认模板文件跳过、--target-name 派生。
  9. status 准确性:发现的 agent 列表、文件数、路径与实际一致。
  10. 合并(merge)正确性:section 级合并、默认模板注入、不覆盖用户自定义内容。
  11. 凭据/登录路径:未登录时明确提示、--token/--endpoint 覆盖生效、匿名(无 token)下载。
  12. 首次同步 / 冲突处理:无 baseline 首次 push/pull;本地与远端同时改动时的冲突表现。
  13. 安全与边界:zip 还原的路径遍历防护(../)、超限大文件跳过、损坏的 sync state 降级、两个 watch 进程并发竞争同一状态文件。
  14. 网络异常恢复:连接超时 / DNS 失败 / 服务端限流后 watch 的重试与恢复行为。
  15. 实际可用性: 在实际 agent 框架中测试效果,确认可用
  16. 上传脱敏(secret sanitization)正确性:被采集的凭证配置文件在上传时清空密钥、非密钥内容与结构保留
  17. list 功能正确性ms-agent agent list--owner 过滤、分页(--page/--page-size)、空结果提示、返回字段解析(repo_id/framework/visibility/updated)正确;--token/--endpointms login/环境变量的凭据回退生效。

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request migrates the agent workspace management business logic from modelscope-hub to ms-agent, introducing a comprehensive suite of CLI commands (upload, download, convert, watch, etc.) and a section-level Markdown merge engine to support cross-framework agent migration. Feedback on these changes highlights several areas for improvement: using a comment-preserving YAML parser or regex for config.yaml sanitization to avoid stripping user comments; reusing the existing tabulate utility in _commands.py to reduce duplication; explicitly specifying UTF-8 encoding when reading and writing temporary files and PID files in _watcher.py for Windows compatibility; and logging a warning when files are silently skipped due to exceeding size limits in _workspace.py.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread ms_agent/agent_hub/frameworks/hermes.py Outdated
Comment thread ms_agent/agent_hub/_commands.py Outdated
Comment thread ms_agent/agent_hub/_watcher.py Outdated
Comment thread ms_agent/agent_hub/_watcher.py
Comment thread ms_agent/agent_hub/_watcher.py
Comment thread ms_agent/agent_hub/_workspace.py
@tastelikefeet tastelikefeet changed the title [WIP]Support agenthub Support agenthub Jul 13, 2026
Comment thread ms_agent/agent_hub/_commands.py Outdated
Comment thread ms_agent/agent_hub/_sync.py
@tastelikefeet tastelikefeet merged commit 6bb17fa into modelscope:main Jul 16, 2026
0 of 2 checks passed
@tastelikefeet tastelikefeet deleted the feat/agenthub branch July 16, 2026 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants